package edu.cuit.avatar.generic;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/10 9:00
 */
public class Rectangle extends Geometric
        implements Comparable<Rectangle>{
    private float width;

    private float height;

    public Rectangle(float width, float height) {
        this.width = width;
        this.height = height;
    }

    public Rectangle(float width, float height, String color, boolean filled) {
        super(color, filled);
        this.width = width;
        this.height = height;
    }

    public float getWidth() {
        return width;
    }

    public void setWidth(float width) {
        this.width = width;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    /**
     * 计算面积
     * @return 面积
     */
    public float getArea(){
        return width * height;
    }

    /**
     * 计算周长
     * @return 周长
     */
    public float getPerimeter(){
        return 2 * (width + height);
    }

    /**
     * 该方法制定排序的规则
     * this < o return 小于0的整数
     * this == o return 0
     * this > o return 大于0的整数
     * @param o the object to be compared.
     * @return 根据面积进行排序
     */
    @Override
    public int compareTo(Rectangle o) {
        //return getArea() > o.getArea() ? 1 : getArea() == o.getArea() ? 0 : -1;
        return Float.compare(getPerimeter(), o.getPerimeter());
    }
}
